import java.util.Date;
import java.util.Timer;


public class TimingTaskLauncher {

	Timer timer = new Timer(); 
	
	public void launch(TimingTask t){
		cancel();
		timer.schedule(t, t.dueTime);
	}
	
	public void cancel(){
		timer.cancel();
		timer=null;
		timer=new Timer();
	}
	
	private static void main(String[] args) {
		TimingTaskLauncher launcher =new TimingTaskLauncher();
		Date now =new Date();
		System.out.println(now);
		launcher.launch(new EmailTask("1",new Date(now.getTime()+5000)));
		System.out.println("2");
		//launcher.cancel();
	}
}

